package com.antg;

import java.util.HashMap;
import java.util.Map;

/**
 * 1. 两数之和
 *
 * @author Antg
 * @date 2021/10/19  12:36
 */
public class Code_1 {
    public static void main(String[] args) {
        System.out.println("123");
    }
    public int[] twoSum(int[] nums, int target) {
        //存储target-num[i] 和 对应的下标
        Map<Integer,Integer> map = new HashMap<>();
        for(int i = 0;i<nums.length;i++){
            if(map.containsKey(nums[i])){
                return new int[]{map.get(nums[i]),i};
            }else{
                map.put(target-nums[i],i);
            }
        }
        return null;
    }
}
